<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style media="screen">
            * {
                padding: 0;
                margin: 0;

            }
        </style>
    </head>
    <body>
        <h1></h1>

    </body>
    <script type="text/javascript">


        var timer=null;
        function showDate(year,month,day,h1){
            var now = new Date();
            var endDate = new Date(year, month-1, day);
            // 结束日期的毫秒数减去现在日期的毫秒数
            var time=endDate.getTime()-now.getTime();
            // 以毫秒计算
            var time1 = parseInt(time/1000);
            // 计算天数
            var day1=Math.floor(time1/(60*60*24));
            //计算小时
            var hour=Math.floor((time1-day1*24*60*60)/3600);
            // 计算分钟
            var minute=Math.floor((time1-day1*24*60*60-hour*3600)/60);
            // 计算秒数
            var second=Math.floor(time1-day1*24*60*60-hour*3600-minute*60);
            // 获取元素
            var h1=document.querySelector('h1');
            h1.innerHTML="距离"+year+"年"+month+"月"+day+"日还有："+day1+"天"+hour+"小时"+minute+"分"+second+"秒";
        }
        clearInterval(timer);
        timer=setInterval(function(){
            showDate(2017,5,1,'h1');
        }, 1000);



    </script>
</html>
